import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		user_name: "",
		password:"",
		logined:false,
		msgs:[
				// {
				// 	is_readed:false,
				// 	content:"编号0025号猪的体温过高，请及时处理"
				// },
				// {
				// 	is_readed:false,
				// 	content:"编号0065号母猪发情了"
				// },
				// {
				// 	is_readed:false,
				// 	content:"编号0015号母猪发情了"
				// }							
			],
		count:0,
	},
	mutations: {
		globalLogin(state, user) {
			console.log(66666)
			state.user_name = user.user_name;
			state.password = user.password;
			state.logined = true;
		},
		globalLogout(state) {
			state.user_name = "";
			state.logined = false;
		},
		addMsg(state,msg){
			let obj={
				is_readed:false,
				content:msg
			};
			state.msgs.push(obj);
		},
		setIsReaded(state,index){
			state.msgs[index].is_readed=true;
		},
		plusCount(state){
			state.count++;
		},
			
		minusCount(state){
			state.count--;
		}
	}
})

export default store
